using System.Web;
using Medianamik.Core.Sugar;

namespace Medianamik.Core.DAL.Services
{
    public class ContentStateService : IContentStateService
    {
        public ContentState GetCurrentContentState()
        {
            return HttpContext.Current == null ? ContentState.Published
                       : GetGeneration(HttpContext.Current.Request);
        }

        private ContentState GetGeneration(HttpRequest pRequest)
        {
            if (pRequest.Url.PathAndQuery.ContainsCaseInsensitive("/medianamik/"))
                return ContentState.Draft;

            var mkgParam = pRequest["mkg"];
            int mkg;
            return int.TryParse(mkgParam, out mkg) ? (ContentState)mkg : ContentState.Published;
        }
    }
}